/*
*Author 		Gina Maya Purnama
*DateCreated	5 April 2011
*DateModified	6 April
*Version		1.1
*/

package jtk.project4.fleet.screen.addAccidentEntry;

import java.awt.FlowLayout;

import jtk.project4.fleet.field.AccidentLocationField;
import jtk.project4.fleet.field.GeneralInformationAccidentField;
import jtk.project4.fleet.field.GeneralInformationField;
import jtk.project4.fleet.field.NotesAccidentField;
import jtk.project4.fleet.field.PhotoAccidentField;
import jtk.project4.fleet.field.PoliceAccidentField;
import jtk.project4.fleet.field.TombolPhotoAccidentField;
import nl.coderight.jazz.form.FormField;
import nl.coderight.jazz.form.FormHeader;
import nl.coderight.jazz.form.FormLayout;
import nl.coderight.jazz.form.FormView;
import nl.coderight.jazz.form.control.GroupControl;
import nl.coderight.jazz.form.control.TabControl;
import nl.coderight.jazz.form.control.TabItem;
import nl.coderight.jazz.form.field.button.PushButton;


public class AddAccidentEntryView extends FormView{
	private FormHeader formHeader;
	private TabControl accidentEntryTab;
	private TabItem generalInformationAccidentTab;
	private TabItem policeTab;
	private TabItem notesTab;
	private TabItem photoTab;

	private PushButton saveButton;
	private PushButton cancelButton;

	
	
	@Override
	protected void init() {
		createTabFields();		
		createFields();
		createLayout();
		//setResizable(false);
	}
	
	private FormHeader createHeader() {
		formHeader = new FormHeader();
		formHeader.setTitle("add.AccidentEntry.header.form");
		return formHeader;
	}
	
	private void createLayout() {
		setHeader(createHeader());
		addField(createForm());
	}
	
	private void createFields() {
		saveButton = new PushButton("saveAction");
		cancelButton = new PushButton("cancelAction");
	}
	
	private void createTabFields()
	{
		accidentEntryTab = new TabControl();
		generalInformationAccidentTab = new TabItem("General Information");
		policeTab = new TabItem("Police");
		notesTab = new TabItem("Notes");
		photoTab = new TabItem("Photo");
	}
	
	private FormField createTabs()
	{
		TabControl form = accidentEntryTab;
		form.addTab(generalInformationAccidentTab, createGeneralTab());
		form.addTab(policeTab, createPoliceTab());
		form.addTab(notesTab, notesTab());
		form.addTab(photoTab, photoTab());
		return form;
	}
	
	private GroupControl createGeneralTab() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
		.addField(new GeneralInformationAccidentField("generalInformation"))
		.addRow()
		.addField(new AccidentLocationField("accidentLocation"))
	//	.addField(new NotesAccidentField("notesAccident"))
		;					
		return form;
	}
	
	private GroupControl createPoliceTab() {
		GroupControl form = new GroupControl();
		/*form.setLayout(new FormLayout())
		.addField(new PoliceAccidentField("respondingPoliceUnit"))
		;	*/
		form.addField(new PoliceAccidentField("respondingPoliceUnit"), CENTER);
	
		return form;
	}
	
	private GroupControl notesTab() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
			.addField(new NotesAccidentField("notes"))
		;					
		return form;
	}
	
	private GroupControl photoTab() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
			.addField(new PhotoAccidentField("photo"))
			.addRow()
			.addField(new TombolPhotoAccidentField(""))
		;					
		return form;
	}
	
	private FormField createForm()
	{
		GroupControl form = new GroupControl();		
		form.addField(createTabs());
		form.addField(createButtons(), SOUTH);
		
		return form;
	}
	
	private GroupControl createGeneralForm() {
		GroupControl form = new GroupControl();
		form.addField(createGeneralForm(), NORTH);
		form.addField(createButtons(), SOUTH);
		return form;
	}
	
	private GroupControl createButtons() {
		GroupControl buttons = new GroupControl();
		buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttons.addField(saveButton);
		buttons.addField(cancelButton);
		return buttons;
	}
}

